#include "BackupFSLogger.h"

namespace BackupFS {
	BackupFSLogger* BackupFSLogger::_Instance = nullptr;
	std::recursive_mutex BackupFSLogger::_Locker;
	
	BackupFSLogger::BackupFSLogger()
	{

	}
	void BackupFSLogger::ReleaseInstance()
	{
		if (_Instance)
		{
			delete _Instance;
			_Instance = nullptr;
		}
	}
	BackupFSLogger::~BackupFSLogger()
	{
		if (_LogFile.is_open())
		{
			_LogFile.close();
		}
	}
	/*
	Set the console color,inner use
	*/
	void  BackupFSLogger::_SetColor(int text_color, int bg_color)
	{
		HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
		SetConsoleTextAttribute(hConsole, (bg_color << 4) | text_color);
	}
	/*
	Set log file,if calls this function, the log will be outputed to the file
	*/
	bool BackupFSLogger::SetLogFile(const std::wstring& LogFileName)
	{
		_LogFileName = LogFileName;
		return _OpenLogFile();
	}
	bool BackupFSLogger::_OpenLogFile()
	{
		_LogFile.open(_LogFileName.c_str(), std::ios::out|std::ios::app);
		return _LogFile.is_open();
	}
	/*
	Whether log to console,if ToConsole is false, the log will not be outputed to console
	*/
	void BackupFSLogger::SetToConsole(bool ToConsole)
	{
		_ToConsole = ToConsole;
	}
	void BackupFSLogger::_Log_To_Console()
	{
		std::cout << std::endl;
	}
	void BackupFSLogger::_Log_To_File()
	{
		if (_LogFile.is_open())
		{
			_LogFile << std::endl;
		}
	}
	
}